#include <REGX52.H>
#include "Timer0.h"
#include "Timer1.h"
#include "Key-T0.h"
#include "Delay.h" 
#include "LCD1602.h"


unsigned char Key_Value, flag,number;

void main()
{
	
	LCD_Init();     //LCD1602初始化
	Timer0_Init();  //定时器T0初始化
	Timer1_Init();	//定时器T1初始化
	while(1)
	{
		Key_Value = GetKey_Num();
		
		if(Key_Value == 1)
		{
			flag = 1;	
		}
		if(Key_Value == 2)
		{
			number++;
		}
		if(Key_Value == 3)
		{
			number--;
		}
		
		LCD_ShowNum(1,1,number,2);

		
		
		if(Key_Value == 4&&flag_anjian == 1)
	{
		P2_1=0;
	}
		
	if(Key_Value == 4&&flag_anjian == 2)
	{
		P2_2=0;
	}
	
	}
	
}


//----------------------------------------------------
void Timer0_Routine() interrupt 1  //定时器0的中断函数
{
	static unsigned int T0Count, cnt;
	
	TL0 = 0x66;		//设置定时初值
	TH0 = 0xFC;		//设置定时初值
	T0Count++;
	cnt++;
	
	
	if(flag == 1){
		if(T0Count >= 500){
			P2_0 = ~P2_0;
			T0Count = 0;
		}
		
		}
		
		
		
	
	
}

//-----------------------------------------
void Timer1_Routine() interrupt 3  //定时器1的中断函数
{
	static unsigned int T1Count;//static静态局部变量，只有本函数能引用
	//退出函数不丢失T0Count变量
	TF1 = 0;
	TL1 = 0x66;		//设置定时初值
	TH1 = 0xFC;		//设置定时初值
	T1Count++;  
	
	if(T1Count>=10) //消抖10ms
	{
		KeyScan();
		
		T1Count=0;//清零重记次
		
		
	}
	
	
}
